package org.hackystat.devcathlon.ui.page.matches.manage.matchdeletepanel;

import org.apache.wicket.markup.html.basic.Label;
import org.apache.wicket.markup.html.form.Button;
import org.apache.wicket.markup.html.form.Form;
import org.apache.wicket.markup.html.panel.Panel;
import org.hackystat.devcathlon.engine.match.Match;
import org.hackystat.devcathlon.engine.match.MatchManager;
import org.hackystat.devcathlon.ui.DevcathlonSession;
import org.hackystat.devcathlon.ui.page.matches.MatchesSession;
import org.hackystat.devcathlon.ui.page.matches.manage.MatchesManagePage;

/**
 * Delete a match panel.
 * @author robin
 *
 */
public class MatchDeletePanel extends Panel {
  /** Support serialization. */
  private static final long serialVersionUID = 1L;
  
  /**
   * Creates the match panel.
   * @param id The panel id.
   * @param mItem The match instance.
   */
  public MatchDeletePanel(String id, final Match mItem) {
    super(id);
    
    MatchesSession matchSession = DevcathlonSession.get().getMatchesSession();
    
    // Match name label.
    add(new Label("matchNameLabel", matchSession.getSelectedMatch()));
    
    Form form = new Form("deleteMatchForm") {
      private static final long serialVersionUID = 1L;
      @Override
      public void onSubmit() {
        String matchName = DevcathlonSession.get().getMatchesSession().getSelectedMatch();
        MatchManager.getInstance().deleteMatch(matchName);
        setResponsePage(new MatchesManagePage());
      }
      
    };
    
    Button cancel = new Button("cancelButton") {
      private static final long serialVersionUID = 1L;
      @Override
      public void onSubmit() {
        setResponsePage(new MatchesManagePage());
      }
    };
    form.add(cancel);
    add(form);
  }
}
